var { Action } = require("../../base/index");
var ad = require("../../ads/fanQie/index");
var {
  clickUtils,
  randomUtils,
  textUtils,
  ocrUtils,
  logUtils,
  clickContent,
} = require("../../utils/index");
var pointMap = require("./pointMap");
var aGetTime = new Action("获取时长", {});
aGetTime.goStartPage = function () {
  logUtils.info("开始点击 首页.我的");
  clickUtils.clickPointMap(pointMap.首页.我的);
  sleep(randomUtils.getRandom(3, 5, 1000));
  logUtils.info("开始点击 我的.剩余时长");
  clickUtils.clickPointMap(pointMap.我的.剩余时长);
  sleep(randomUtils.getRandom(3, 5, 1000));
  return true;
};
aGetTime.exec = function () {
  for (var index = 0; index < 10; index++) {
    var content = "看视频领";
    if (clickContent(content)) {
      sleep(randomUtils.getRandom(3, 5, 1000));
      ad.startWatchAd(20);
      continue;
    }
    var content = "分钟后可继续领取";
    var TextUI = textUtils.existsTextEndsWith(content);
    if (TextUI) {
      logUtils.info("分钟后可领取");
      sleep(randomUtils.getRandom(3, 5, 1000));
      return;
    }
    var TextOCR = ocrUtils.captureExistsText(content);
    if (TextOCR) {
      logUtils.info("分钟后可领取");
      sleep(randomUtils.getRandom(3, 5, 1000));
      return;
    }
    var content = "秒后可继续领取";
    var TextUI = textUtils.existsTextEndsWith(content);
    if (TextUI) {
      sleep(randomUtils.getRandom(30, 50, 1000));
      index--;
      continue;
    }
    var TextOCR = ocrUtils.captureExistsText(content);
    if (TextOCR) {
      sleep(randomUtils.getRandom(30, 50, 1000));
      index--;
      continue;
    }
  }
};

module.exports = aGetTime;
